package com.levy.contronller.javase.designModel.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * 被观察者
 * Created by levy on 2018/8/7.
 */
public class Person extends Observable {

    private String name;

    private String sex;

    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        //方法无法自动判断出对象有改变 需要手动通知值改变 如果不手工改动的话 是识别不了变化的
        this.setChanged();
        //发生name变化的时候 通知观察者
        this.notifyObservers();
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
        this.notifyObservers();
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
        this.notifyObservers();
    }


    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}
